package com.rock.platform.util;

public class QueryUtils {
	public static String GetTotalCountSql(String strSql) {
		StringBuffer sb = new StringBuffer("SELECT COUNT(1) FROM (");
		sb.append(strSql);
		sb.append(")");
		return sb.toString();
	}

	public static String GetPageSql(int startIndex, int endIndex, String strSql) {
		if (startIndex < 0) {
			return strSql;
		}

		StringBuffer sb = new StringBuffer(
				"SELECT B.* FROM (SELECT A.*, rownum AS rn FROM (");
		sb.append(strSql);
		sb.append(") A WHERE rownum <=");
		sb.append(endIndex);
		sb.append(") B WHERE rn >=");
		sb.append(startIndex);

		return sb.toString();
	}

	public static String GetLongTimeClause(String strFieldName) {
		return "TO_CHAR(" + strFieldName + ",'YYYY-MM-DD HH24:MI:SS')";
	}

	public static String GetShortTimeClause(String strFieldName) {
		return "TO_CHAR(" + strFieldName + ",'YYYY-MM-DD')";
	}
}
